package gk.example.adapter;

import gk.example.bean.User;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.gkdate.R;

public class OtherInfoAdapter extends BaseAdapter {
	private Context mContext;
	private User mUser;

	public OtherInfoAdapter(Context context, User user) {
		mContext = context;
		mUser = user;
	}

	@Override
	public int getCount() {
		return 3;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		OtherInfoViewHolder otherInfoViewHolder = null;
		if (convertView == null) {
			otherInfoViewHolder = new OtherInfoViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_other_info, parent, false);
			otherInfoViewHolder.title = (TextView) convertView
					.findViewById(R.id.tv_other_info_title);
			otherInfoViewHolder.detail = (TextView) convertView
					.findViewById(R.id.tv_other_info_detail);
			otherInfoViewHolder.sex = (ImageView) convertView
					.findViewById(R.id.image_other_sex);
			convertView.setTag(otherInfoViewHolder);
		} else {
			otherInfoViewHolder = (OtherInfoViewHolder) convertView.getTag();
		}
		switch (position) {
		case 0:
			otherInfoViewHolder.title.setText("昵称");
			otherInfoViewHolder.detail.setText(mUser.getNickName());
			break;
		case 1:
			otherInfoViewHolder.title.setText("性别");
			if (mUser.getSex().equals("男")) {
				otherInfoViewHolder.detail.setText("男");
				otherInfoViewHolder.sex
						.setBackgroundResource(R.drawable.ic_sex_male);
			} else {
				otherInfoViewHolder.detail.setText("女");
				otherInfoViewHolder.sex
						.setBackgroundResource(R.drawable.ic_sex_female);
			}

			break;
		case 2:
			otherInfoViewHolder.title.setText("个人简介");
			if (mUser.getIntroduction()==null) {
				otherInfoViewHolder.detail.setText("这个人什么都没有写");
			} else {
				otherInfoViewHolder.detail.setText(mUser.getIntroduction());
			}
			break;

		default:
			break;
		}
		return convertView;
	}

}

class OtherInfoViewHolder {
	TextView title;
	TextView detail;
	ImageView sex;
}